#!/bin/bash
echo "安装docker(阿里)..."
sudo curl -sSL https://get.docker.com | sh


echo "修改docker镜像源..."
cat >> /etc/docker/daemon.json <<EOF
{
    "registry-mirrors" : [
    "https://registry.docker-cn.com",
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com",
    "https://cr.console.aliyun.com/"
  ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl enable docker
sudo systemctl start docker

echo "更换apt源(阿里)..."
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak

echo "" > /etc/apt/sources.list
echo "" > /etc/apt/sources.list.d/raspi.list

cat >> /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main contrib non-free rpi
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main contrib non-free rpi
EOF

cat >> /etc/apt/sources.list.d/raspi.list <<EOF
deb http://mirrors.aliyun.com/raspberrypi/ buster main ui
deb-src http://mirrors.aliyun.com/raspberrypi/ buster main ui
EOF
echo "更换apt阿里云源完成"


echo "更换pip源（豆瓣）..."
mkdir ~/.pip
cat >> ~/.pip/pip.conf <<EOF
[global]
timeout =6000
index-url =http://pypi.douban.com/simple/
[install]
use-mirrors =true 
mirrors =http://pypi.douban.com/simple/ 
trusted-host =pypi.douban.com
EOF
echo "更换pip源（豆瓣）完成"

echo "更新系统"
sudo apt-get update
sudo apt-get upgrade

echo "开始安装docker-compose..."
sudo apt-get install python3-pip
sudo apt-get install libffi-dev
sudo pip3 install docker-compose


echo "开始安装git..."
sudo apt-get install git

echo "防火墙设置"
sudo apt-get install ufw
sudo ufw enable
sudo ufw default deny
sudo ufw allow 22
sudo ufw allow 80
sudo ufw allow 3306
sudo ufw allow 9000
sudo ufw allow 8080
sudo ufw allow 1883
sudo ufw allow 18083
sudo ufw allow 8083



echo "安装辐射场系统"
git clone https://gitee.com/redfalsh/fsc-system.git
cd fsc-system
sudo docker-compose up

echo "阿里云拉取docker镜像"
sudo docker pull registry.cn-hangzhou.aliyuncs.com/redfalsh/nginx:latest
sudo docker pull registry.cn-hangzhou.aliyuncs.com/redfalsh/emqx:latest
sudo docker pull registry.cn-hangzhou.aliyuncs.com/redfalsh/rpi-mysql:latest	
sudo docker pull registry.cn-hangzhou.aliyuncs.com/redfalsh/golang:alpine

